package com.ddwl.gate.util;


import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.common.util.UUIDGenerator;
import com.ddwl.gate.dao.DingTalkRecordDao;
import com.ddwl.schema.vo.gate.DingTalkRecordVo;
import com.ddwl.gate.model.DingTalkRecord;
import com.ddwl.schema.util.DateUtil;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.Instant;
import java.util.List;

/**
 * @className: RobotHelperUtil
 * @description: 机器人工具类
 *      每个机器人每分钟最多发送20条
 *      限制6 个机器人/群
 * @author wenbin
 * @Date :2020-06-02 14:23.
 */
@Service
@RefreshScope
@Slf4j
public class RobotHelperUtil {

    private static DingTalkRecordDao dingTalkRecordDao;

    @Resource
    public void setDingTalkRecordDao(DingTalkRecordDao dingTalkRecordDao) {
        RobotHelperUtil.dingTalkRecordDao = dingTalkRecordDao;
    }

    /**
     * 钉钉群设置 webhook, 支持重置
     */
    private static final String ACCESS_TOKEN_PRE_FIX = "https://oapi.dingtalk.com/robot/send?access_token=";

    /**
     * 消息类型
     */
    private static final String MSG_TYPE_TEXT = "text";
    private static final String MSG_TYPE_LINK = "link";
    private static final String MSG_TYPE_MARKDOWN = "markdown";
    private static final String MSG_TYPE_ACTION_CARD = "actionCard";
    private static final String MSG_TYPE_FEED_CARD = "feedCard";

    //@Value("${dingtalk.message_robot.access_token}")
    private static String ACCESS_TOKEN;

    @Value(value="${dingtalk.message_robot.access_token}")
    public void setAccessToken(String accessToken){
        ACCESS_TOKEN = accessToken;
    }

    //@Value("${dingtalk.agentId}")
    private static Long AGENT_ID;

    @Value(value="${dingtalk.agentId}")
    public void setAgentId(Long agentId){
        AGENT_ID = agentId;
    }

    //@Value("${dingtalk.appKey}")
    private static String APP_KEY;

    @Value(value="${dingtalk.appKey}")
    public void setAppKey(String appKey){
        APP_KEY = appKey;
    }

    //@Value("${dingtalk.appSecret}")
    private static String APP_SECRET;

    @Value(value="${dingtalk.appSecret}")
    public void setAppSecret(String appSecret){
        APP_SECRET = appSecret;
    }

    /**
     * 客户端实例
     */
    public static DingTalkClient client = null;
    private static AccessTokenlin Atl;


    public static DingTalkClient getDingTalkClient(){
        if(client == null){
                client = new DefaultDingTalkClient(ACCESS_TOKEN_PRE_FIX+ACCESS_TOKEN);
        }
        return client;
    }

    /**
     * @description: 官方演示示例
     *      title 是消息列表下透出的标题
     *      text 是进入群后看到的消息内容
     *
     * @author: niaonao
     * @date: 2019/7/6
     */
    public void sdkDemoJava() {
        DingTalkClient client = RobotHelperUtil.client;
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("text");
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        text.setContent("多典通知:测试文本消息\n多典通知");
        request.setText(text);
        OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
        //at.setAtMobiles(Arrays.asList("18840867991"));
        request.setAt(at);

/*        request.setMsgtype("link");
        OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
        link.setMessageUrl("https://www.dingtalk.com/");
        link.setPicUrl("");
        link.setTitle("时代的火车向前开"+"多典通知");
        link.setText("这个即将发布的新版本，创始人陈航（花名“无招”）称它为“红树林”。\n" +
                "而在此之前，每当面临重大升级，产品经理们都会取一个应景的代号，这一次，为什么是“红树林"+"多典通知");
        request.setLink(link);*/

/*        request.setMsgtype("markdown");
        OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
        markdown.setTitle("杭州天气"+"多典通知");
        markdown.setText("#### 杭州天气 @156xxxx8827\n" +
                "> 9度，西北风1级，空气良89，相对温度73%\n\n" +
                "> ![screenshot](https://gw.alipayobjects.com/zos/skylark-tools/public/files/84111bbeba74743d2771ed4f062d1f25.png)\n"  +
                "> ###### 10点20分发布 [天气](http://www.thinkpage.cn/) \n"+"多典通知");
        request.setMarkdown(markdown);*/
        try {
            client.execute(request);
        } catch (ApiException e) {
            log.error("[ApiException]: 消息发送演示示例, 异常捕获{}", e.getMessage());
        }
    }

    /**
     * 多典推送消息
     */
    public static void sendDingMessage(String message, String mobiles) {
        DingTalkClient client = getDingTalkClient();
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype("text");
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        message = message.replaceAll(",", "\n");
        String dateTime = DateUtil.formatDateTime(Instant.now());
        text.setContent(dateTime+" 多典通知:\n"+message);
        request.setText(text);
        //OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
        //具体通知某人
        //at.setAtMobiles("18840867991");
        //at.setAtMobiles(mobiles);
        //request.setAt(at);
        //OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            client.execute(request);
            //插入发送记录
            DingTalkRecordVo record=new DingTalkRecordVo();
            record.setContent(message);
            record.setSendUser(mobiles);
            record.setSendTime(dateTime);
            dingRecord(record);
        } catch (ApiException e) {
            log.error("[ApiException]: 推送钉钉消息异常, 异常捕获{}", e.getMessage());
        }
    }

    /**
     * @description: 发送普通文本消息
     * @param content   文本消息
     * @param mobileList    指定@ 联系人
     * @param isAtAll       是否@ 全部联系人
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByText(String content, List<String> mobileList, boolean isAtAll) {
        if (!StringUtils.hasText(content)) {
            return null;
        }

        //参数	参数类型	必须	说明
        //msgtype	String	是	消息类型，此时固定为：text
        //content	String	是	消息内容
        //atMobiles	Array	否	被@人的手机号(在content里添加@人的手机号)
        //isAtAll	bool	否	@所有人时：true，否则为：false
        OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
        text.setContent(content);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        if (!CollectionUtils.isEmpty(mobileList)) {
            // 发送消息并@ 以下手机号联系人
            OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
            at.setAtMobiles(mobileList);
            at.setIsAtAll(isAtAll ? true : false);
            request.setAt(at);
        }
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_TEXT);
        request.setText(text);

        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送普通文本消息]: 发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }

    /**
     * @description: 发送link 类型消息
     * @param title 消息标题
     * @param text  消息内容
     * @param messageUrl     点击消息后跳转的url
     * @param picUrl    插入图片的url
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByLink(String title, String text, String messageUrl, String picUrl) {
        if (!checkNotEmpty(title, text, messageUrl)) {
            return null;
        }
        //参数	参数类型	必须	说明
        //msgtype	String	是	消息类型，此时固定为：link
        //title	String	是	消息标题
        //text	String	是	消息内容。如果太长只会部分展示
        //messageUrl	String	是	点击消息跳转的URL
        //picUrl	String	否	图片URL
        OapiRobotSendRequest.Link link = new OapiRobotSendRequest.Link();
        link.setTitle(title);
        link.setText(text);
        link.setMessageUrl(messageUrl);
        link.setPicUrl(picUrl);

        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_LINK);
        request.setLink(link);

        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送link 类型消息]: 发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }


    /**
     * @description: 发送Markdown 编辑格式的消息
     * @param title 标题
     * @param markdownText  支持markdown 编辑格式的文本信息
     * @param mobileList    消息@ 联系人
     * @param isAtAll   是否@ 全部
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByMarkdown(String title, String markdownText, List<String> mobileList, boolean isAtAll) {
        if (!checkNotEmpty(title, markdownText)) {
            return null;
        }
        //参数	类型	必选	说明
        //msgtype	String	是	此消息类型为固定markdown
        //title	String	是	首屏会话透出的展示内容
        //text	String	是	markdown格式的消息
        //atMobiles	Array	否	被@人的手机号(在text内容里要有@手机号)
        //isAtAll	bool	否	@所有人时：true，否则为：false
        OapiRobotSendRequest.Markdown markdown = new OapiRobotSendRequest.Markdown();
        markdown.setTitle(title);
        markdown.setText(markdownText);

        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_MARKDOWN);
        request.setMarkdown(markdown);
        if (!CollectionUtils.isEmpty(mobileList)) {
            OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
            at.setIsAtAll(isAtAll ? true : false);
            at.setAtMobiles(mobileList);
            request.setAt(at);
        }

        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送link 类型消息]: 发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }

    /**
     * @description: 整体跳转ActionCard类型的消息发送
     * @param title 消息标题, 会话消息会展示标题
     * @param markdownText  markdown格式的消息
     * @param singleTitle   单个按钮的标题
     * @param singleURL 单个按钮的跳转链接
     * @param btnOrientation    是否横向排列(true 横向排列, false 纵向排列)
     * @param hideAvatar    是否隐藏发消息者头像(true 隐藏头像, false 不隐藏)
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByActionCardSingle(String title, String markdownText, String singleTitle, String singleURL, boolean btnOrientation, boolean hideAvatar) {
        if (!checkNotEmpty(title, markdownText)) {
            return null;
        }
        //参数	类型	必选	说明
        //    msgtype	string	true	此消息类型为固定actionCard
        //    title	string	true	首屏会话透出的展示内容
        //    text	string	true	markdown格式的消息
        //    singleTitle	string	true	单个按钮的方案。(设置此项和singleURL后btns无效)
        //    singleURL	string	true	点击singleTitle按钮触发的URL
        //    btnOrientation	string	false	0-按钮竖直排列，1-按钮横向排列
        //    hideAvatar	string	false	0-正常发消息者头像，1-隐藏发消息者头像
        OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard();
        actionCard.setTitle(title);
        actionCard.setText(markdownText);
        actionCard.setSingleTitle(singleTitle);
        actionCard.setSingleURL(singleURL);
        // 此处默认为0
        actionCard.setBtnOrientation(btnOrientation ? "1" : "0");
        // 此处默认为0
        actionCard.setHideAvatar(hideAvatar ? "1" : "0");

        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_ACTION_CARD);
        request.setActionCard(actionCard);
        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送ActionCard 类型消息]: 整体跳转ActionCard类型的发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }

    /**
     * @description: 独立跳转ActionCard类型 消息发送
     * @param title 标题
     * @param markdownText  文本
     * @param btns  按钮列表
     * @param btnOrientation    是否横向排列(true 横向排列, false 纵向排列)
     * @param hideAvatar    是否隐藏发消息者头像(true 隐藏头像, false 不隐藏)
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByActionCardMulti(String title, String markdownText, List<OapiRobotSendRequest.Btns> btns, boolean btnOrientation, boolean hideAvatar) {
        if (!checkNotEmpty(title, markdownText) || CollectionUtils.isEmpty(btns)) {
            return null;
        }
        //参数	类型	必选	说明
        //msgtype	string	true	此消息类型为固定actionCard
        //title	string	true	首屏会话透出的展示内容
        //text	string	true	markdown格式的消息
        //btns	array	true	按钮的信息：title-按钮方案，actionURL-点击按钮触发的URL
        //btnOrientation	string	false	0-按钮竖直排列，1-按钮横向排列
        //hideAvatar	string	false	0-正常发消息者头像，1-隐藏发消息者头像
        OapiRobotSendRequest.Actioncard actionCard = new OapiRobotSendRequest.Actioncard();
        actionCard.setTitle(title);
        actionCard.setText(markdownText);
        // 此处默认为0
        actionCard.setBtnOrientation(btnOrientation ? "1" : "0");
        // 此处默认为0
        actionCard.setHideAvatar(hideAvatar ? "1" : "0");

        actionCard.setBtns(btns);

        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_ACTION_CARD);
        request.setActionCard(actionCard);
        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送ActionCard 类型消息]: 独立跳转ActionCard类型发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }

    /**
     * @description: 发送FeedCard类型消息
     * @param links
     * @return: com.dingtalk.api.response.OapiRobotSendResponse
     * @author: niaonao
     * @date: 2019/7/6
     */
    public static OapiRobotSendResponse sendMessageByFeedCard(List<OapiRobotSendRequest.Links> links) {
        if (CollectionUtils.isEmpty(links)) {
            return null;
        }

        //msgtype	string	true	此消息类型为固定feedCard
        //title	string	true	单条信息文本
        //messageURL	string	true	点击单条信息到跳转链接
        //picURL	string	true	单条信息后面图片的URL
        OapiRobotSendRequest.Feedcard feedcard = new  OapiRobotSendRequest.Feedcard();
        feedcard.setLinks(links);
        OapiRobotSendRequest request = new OapiRobotSendRequest();
        request.setMsgtype(RobotHelperUtil.MSG_TYPE_FEED_CARD);
        request.setFeedCard(feedcard);
        OapiRobotSendResponse response = new OapiRobotSendResponse();
        try {
            response = RobotHelperUtil.client.execute(request);
        } catch (ApiException e) {
            log.error("[发送ActionCard 类型消息]: 独立跳转ActionCard类型发送消息失败, 异常捕获{}", e.getMessage());
        }
        return response;
    }

/*    public static void main(String args[]) {
        sdkDemoJava();
    }*/

    private static boolean checkNotEmpty(String a, String b){
        if (StringUtils.hasText(a)&&StringUtils.hasText(b)){
            return true;
        }
        return false;
    }
    private static boolean checkNotEmpty(String a, String b,String c){
        if (StringUtils.hasText(a)&&StringUtils.hasText(b)){
            return true;
        }
        return false;
    }

    private static String getAccessToken() throws Exception {
        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest request = new OapiGettokenRequest();
        request.setAppkey(APP_KEY);
        request.setAppsecret(APP_SECRET);
        request.setHttpMethod("GET");
        OapiGettokenResponse response = client.execute(request);
        String accessToken = response.getAccessToken();
        //将获取的AccessToken和它的过期时间封装到一个AccessToken类中
        Atl = new AccessTokenlin(accessToken, "7200");
        return accessToken;
    }

    public static String GetAccessToken() throws Exception {
        //这里我们需要判断一下Accesstoken是否过期，然后才将其返回
        if(Atl==null||Atl.isExpired()||!StringUtils.hasText(Atl.getAccessToken())) {
            getAccessToken();
        }
        return Atl.getAccessToken();
    }

    /**
     *获取子部门列表
     */
    public static List<OapiDepartmentListResponse.Department> getDeptList() {
        DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/department/list");
        OapiDepartmentListRequest request1=new OapiDepartmentListRequest();
        request1.setId("1");
        request1.setHttpMethod("GET");
        try {
            OapiDepartmentListResponse response1 = client1.execute(request1, GetAccessToken());
            List<OapiDepartmentListResponse.Department> department1 = response1.getDepartment();
            return department1;
        } catch (ApiException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取部门下的所有用户列
     * @param departmentId
     * @return
     */
    public static List<OapiUserSimplelistResponse.Userlist> getDepartmentUser(Long departmentId){

        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/simplelist");
        OapiUserSimplelistRequest request = new OapiUserSimplelistRequest();
        request.setDepartmentId(departmentId);
        request.setOffset(0L);
        request.setSize(50L);
        request.setHttpMethod("GET");

        try {
            OapiUserSimplelistResponse response = client.execute(request, getAccessToken());
            List<OapiUserSimplelistResponse.Userlist> userlist = response.getUserlist();
            return userlist;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据电话查询id
     * @param mobile
     * @return
     */
    public static String getUserByMobile(String mobile){

        DingTalkClient client1 = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/get_by_mobile");
        OapiUserGetByMobileRequest request1 = new OapiUserGetByMobileRequest();
        request1.setMobile(mobile);

        try {
            OapiUserGetByMobileResponse execute = client1.execute(request1, getAccessToken());
            return execute.getUserid();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取部门下的所有用户详情
     * @param departmentId
     * @return
     */
    public static List<OapiUserListbypageResponse.Userlist> getDepartmentUserDetail(Long departmentId){
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
        OapiUserListbypageRequest request = new OapiUserListbypageRequest();
        request.setDepartmentId(departmentId);
        request.setOffset(0L);
        request.setSize(20L);
        request.setHttpMethod("GET");
        try {
            OapiUserListbypageResponse response = client.execute(request, getAccessToken());
            List<OapiUserListbypageResponse.Userlist> userlist = response.getUserlist();
            return userlist;
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 发送通知信息
     * @throws ApiException
     * @throws Exception
     */
    public static void sendMsg(String userIds,String message,String mobiles) throws ApiException, Exception {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");

        OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
        //传入的是员工的工号
        request.setUseridList(userIds);
        //申请的应用AgentId
        request.setAgentId(AGENT_ID);
        //true为全体员工
        request.setToAllUser(false);

        OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
        msg.setMsgtype("text");
        msg.setText(new OapiMessageCorpconversationAsyncsendV2Request.Text());
        String dateTime = DateUtil.formatDateTime(Instant.now());
        message= "推送时间:"+dateTime+"\n"+message.replaceAll(",","\n");
        msg.getText().setContent(message);
        request.setMsg(msg);

    	 /*//发送图片
    	msg.setMsgtype("image");
    	msg.setImage(new OapiMessageCorpconversationAsyncsendV2Request.Image());
    	msg.getImage().setMediaId("@lADOdvRYes0CbM0CbA");
    	request.setMsg(msg);
    	/*
		//发送文件
    	msg.setMsgtype("file");
    	msg.setFile(new OapiMessageCorpconversationAsyncsendV2Request.File());
    	msg.getFile().setMediaId("@lADOdvRYes0CbM0CbA");
    	request.setMsg(msg);
		//发送链接
    	msg.setMsgtype("link");
    	msg.setLink(new OapiMessageCorpconversationAsyncsendV2Request.Link());
    	msg.getLink().setTitle("test");
    	msg.getLink().setText("test");
    	msg.getLink().setMessageUrl("test");
    	msg.getLink().setPicUrl("test");
    	request.setMsg(msg);

    	msg.setMsgtype("markdown");
    	msg.setMarkdown(new OapiMessageCorpconversationAsyncsendV2Request.Markdown());
    	msg.getMarkdown().setText("##### text");
    	msg.getMarkdown().setTitle("### Title");
    	request.setMsg(msg);

    	msg.setOa(new OapiMessageCorpconversationAsyncsendV2Request.OA());
    	msg.getOa().setHead(new OapiMessageCorpconversationAsyncsendV2Request.Head());
    	msg.getOa().getHead().setText("head");
    	msg.getOa().setBody(new OapiMessageCorpconversationAsyncsendV2Request.Body());
    	msg.getOa().getBody().setContent("xxx");
    	msg.setMsgtype("oa");
    	request.setMsg(msg);
    	//发送的文本信息+url
    	msg.setActionCard(new OapiMessageCorpconversationAsyncsendV2Request.ActionCard());
    	msg.getActionCard().setTitle("xxx123411111");
    	msg.getActionCard().setMarkdown("### 测试123111");
    	msg.getActionCard().setSingleTitle("接入钉钉发送通知接口");
    	msg.getActionCard().setSingleUrl("https://www.baidu.com");
    	msg.setMsgtype("action_card");
    	request.setMsg(msg);
		*/
        OapiMessageCorpconversationAsyncsendV2Response response = client.execute(request,GetAccessToken());
        //插入发送记录
        DingTalkRecordVo record=new DingTalkRecordVo();
        record.setContent(message);
        record.setSendUser(mobiles);
        record.setSendTime(dateTime);
        dingRecord(record);
    }

    public static void dingRecord(DingTalkRecordVo record){
        DingTalkRecord dingTalkRecord = BeanConverUtils.convertBean(record, DingTalkRecord.class);
        dingTalkRecord.setId(UUIDGenerator.getShortUUID());
        dingTalkRecordDao.insert(dingTalkRecord);
    }


}
